//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.UIDesigner
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using Microsoft.Research.ScientificWorkflow.TridentModel;
    using Microsoft.Research.ScientificWorkflow.TridentUtilities;

    /// <summary>
    /// Creates an appropriate tooltip.
    /// </summary>
    public class OutputPropertyListNameTooltipGenerator : IValueConverter
    {
        /// <summary>
        /// Convert based on value and parameter.
        /// </summary>
        /// <param name="value">
        /// The current value.
        /// </param>
        /// <param name="targetType">
        /// The expected type.
        /// </param>
        /// <param name="parameter">
        /// Passed parameter.
        /// </param>
        /// <param name="culture">
        /// Culture.
        /// </param>
        /// <returns>
        /// Modified value.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ParameterDescriptionModel paramModel = value as ParameterDescriptionModel;
            if (paramModel != null)
            {
                return OutputPropertyListNameTooltipGenerator.CreateParamTooltip(paramModel);
            }

            return value;
        }

        /// <summary>
        /// Convert back based on value and parameter.
        /// </summary>
        /// <param name="value">
        /// The current value.
        /// </param>
        /// <param name="targetType">
        /// The expected type.
        /// </param>
        /// <param name="parameter">
        /// Passed parameter.
        /// </param>
        /// <param name="culture">
        /// Culture.
        /// </param>
        /// <returns>
        /// Old value.
        /// </returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }

        /// <summary>
        /// Creates Tooltip for Parameter
        /// </summary>
        private static StackPanel CreateParamTooltip(ParameterDescriptionModel paramModel)
        {
            StackPanel topPanel = new StackPanel();
            TextBlock activityName = new TextBlock();
            TextBlock propertyName = new TextBlock();

            string activity = paramModel.PropertyPaneDisplayName.Substring(0, paramModel.PropertyPaneDisplayName.IndexOf('.'));
            activityName.Text = TridentResourceManager.GetString("PropertyPaneTooltipActivity") + activity;
            propertyName.Text = TridentResourceManager.GetString("PropertyPaneTooltipProperty") + paramModel.PropertyName;

            topPanel.Children.Add(activityName);
            topPanel.Children.Add(propertyName);

            if (null != paramModel.DataType)
            {
                TextBlock dataType = new TextBlock();
                dataType.Text = TridentResourceManager.GetString("PropertyPaneTooltipDatatype") + paramModel.DataType.ToString();
                topPanel.Children.Add(dataType);
            }

            if (null != paramModel.Description)
            {
                TextBlock description = new TextBlock();
                description.TextWrapping = TextWrapping.Wrap;
                description.Text = TridentResourceManager.GetString("PropertyPaneTooltipDesc") + paramModel.Description;
                topPanel.Children.Add(description);

            }
            if (!string.IsNullOrEmpty(paramModel.OutputLabel))
            {
                TextBlock outputLabel = new TextBlock();
                outputLabel.Text = TridentResourceManager.GetString("PropertyPaneTooltipOutputLabel") + paramModel.OutputLabel;
                topPanel.Children.Add(outputLabel);
            }

            if (!string.IsNullOrEmpty(paramModel.OutputType))
            {
                TextBlock outputType = new TextBlock();
                outputType.Text = TridentResourceManager.GetString("PropertyPaneTooltipOutputType") + paramModel.OutputType;
                topPanel.Children.Add(outputType);
            }

            return topPanel;
        }
    }


    /// <summary>
    /// Creates an appropriate tooltip.
    /// </summary>
    public class WorkflowOutputsTabTooltipGenerator : IValueConverter
    {
        /// <summary>
        /// Convert based on value and parameter.
        /// </summary>
        /// <param name="value">
        /// The current value.
        /// </param>
        /// <param name="targetType">
        /// The expected type.
        /// </param>
        /// <param name="parameter">
        /// Passed parameter.
        /// </param>
        /// <param name="culture">
        /// Culture.
        /// </param>
        /// <returns>
        /// Modified value.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ParameterDescriptionModel paramModel = value as ParameterDescriptionModel;
            if (paramModel != null)
            {
                return WorkflowOutputsTabTooltipGenerator.CreateParamTooltip(paramModel);
            }

            return value;
        }

        /// <summary>
        /// Convert back based on value and parameter.
        /// </summary>
        /// <param name="value">
        /// The current value.
        /// </param>
        /// <param name="targetType">
        /// The expected type.
        /// </param>
        /// <param name="parameter">
        /// Passed parameter.
        /// </param>
        /// <param name="culture">
        /// Culture.
        /// </param>
        /// <returns>
        /// Old value.
        /// </returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }

        /// <summary>
        /// Creates Tooltip for Parameter
        /// </summary>
        private static StackPanel CreateParamTooltip(ParameterDescriptionModel paramModel)
        {
            StackPanel topPanel = new StackPanel();

            if (!string.IsNullOrEmpty(paramModel.OutputLabel))
            {
                TextBlock outputLabel = new TextBlock();
                outputLabel.Text = TridentResourceManager.GetString("PropertyPaneTooltipOutputLabel") + paramModel.OutputLabel;
                topPanel.Children.Add(outputLabel);
            }

            if (!string.IsNullOrEmpty(paramModel.OutputType))
            {
                TextBlock outputType = new TextBlock();
                outputType.Text = TridentResourceManager.GetString("PropertyPaneTooltipOutputType") + paramModel.OutputType;
                topPanel.Children.Add(outputType);
            }

            return topPanel;
        }
    }
}
